package com.yonyou.pmclouds.billview.conf;

import com.yonyou.pmclouds.basecom.consts.BillTypeConst;
import com.yonyou.pmclouds.billview.rmiimpl.BillViewWrapServiceImpl;
import com.yonyou.pmclouds.billview.rmitf.BillViewWrapService;
import com.yonyou.pmclouds.billview.rmitf.IBillViewBuziService;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class BillViewConfiguration implements BeanPostProcessor {

    private BillViewWrapService billViewWrapServiceImp = new BillViewWrapServiceImpl();

    @Bean
    public BillViewWrapService billViewWrapService() {
        return billViewWrapServiceImp;
    }

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if(bean instanceof IBillViewBuziService){
            IBillViewBuziService service = ((IBillViewBuziService)bean);
            if(BillTypeConst.SITEINSPECTION_BILLTYPE .equals(service.getBillType()) ){
                billViewWrapServiceImp.addBuziService(BillTypeConst.PARALLEL_INSPECTION_BILLTYPE,service);
                billViewWrapServiceImp.addBuziService(BillTypeConst.SIDE_INSPECTION_BILLTYPE ,service);
                billViewWrapServiceImp.addBuziService(BillTypeConst.PATROL_BILLTYPE ,service);
            }else{
                billViewWrapServiceImp.addBuziService(service.getBillType(),service);
            }
        }

        return bean;
    }
}
